import { showToast } from "vant";
import HomeView from "../views/HomeView.vue";

export const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    // 首页
    {
        path: '/home',
        name: 'home',
        component: HomeView,
    },
    // 装修
    {
        path: '/renovation',
        name: 'renovation',
        component: () => import("../views/renovationView.vue")
    },
    // 我家
    {
        path: '/myhome',
        name: 'myhome',
        component: () => import("../views/MyHomeView.vue")
    },
    // 好物
    {
        path: '/goodthing',
        name: 'goodthing',
        component: () => import("../views/GoodThing.vue")
    },
    // 详情页
    {
        path: '/detail',
        name: 'detail',
        component: () => import("../views/DetailView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 发现页详情页
    {
        path: '/detailesr',
        name: 'detailesr',
        component: () => import("../views/DetailesrView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 登录界面
    {
        path: '/LoginView',
        name: 'LoginView',
        component: () => import("../views/LoginView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 注册界面
    {
        path: '/RegisterView',
        name: 'RegisterView',
        component: () => import("../views/RegisterView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 用户中心
    {
        path: '/UserCenter',
        name: 'UserCenter',
        component: () => import("../views/UserCenter.vue"),
        // beforeEnter: (to: any, from: any, next: any) => {
        //     let token = window.localStorage.getItem('token')
        //     if (token == undefined) {
        //         next('/LoginView')
        //     } else {
        //         next()
        //     }

        //     console.log("路由独享守卫beforeEnter");
        // },

        beforeEnter: () => {
            // 判断是否登录，没有登录进入登录页面
            let token = window.localStorage.getItem('token')
            if (token == undefined) {
                return { name: 'LoginView' }
            } else {
                return true
            }

        }
    },
    // 搜索
    {
        path: '/SearchView',
        name: 'SearchView',
        component: () => import("../views/SearchView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 搜索结果
    {
        path: '/SearchResPreView',
        name: 'SearchResPreView',
        component: () => import("../views/SearchResPreView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 装修信息
    {
        path: '/message',
        name: 'message',
        component: () => import("../views/MessageView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 记账记录
    {
        path: '/billrecord',
        name: 'billrecord',
        component: () => import("../views/BillrecordView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 账单明细
    {
        path: '/billdatail',
        name: 'billdatail',
        component: () => import("../views/BilldatailView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 记账
    {
        path: '/billtally',
        name: 'billtally',
        component: () => import("../views/BilltallyView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 足迹
    {
        path: '/FootprintView',
        name: 'FootprintView',
        component: () => import("../views/FootprintView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 关注
    {
        path: '/MyFollowView',
        name: 'MyFollowView',
        component: () => import("../views/MyFollowView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 点赞记录
    {
        path: '/MyLikeRecord',
        name: 'MyLikeRecord',
        component: () => import("../views/MyLikeRecord.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 我的评论
    {
        path: '/RemarkView',
        name: 'RemarkView',
        component: () => import("../views/RemarkView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 草稿箱
    {
        path: '/diary',
        name: 'diary',
        component: () => import("../views/DiaryView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 个人中心
    {
        path: '/conter',
        name: 'conter',
        component: () => import("../views/ConterView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 编辑信息
    {
        path: '/edit',
        name: 'edit',
        component: () => import("../views/EditView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    // 好物分类详情页
    {
        path: '/buy',
        name: 'buy',
        component: () => import("../views/BuyView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    //发布
    {
        path: '/RreleaseView',
        name: 'RreleaseView',
        component: () => import("../views/RreleaseView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        },

        beforeEnter: () => {
            // 判断是否登录，没有登录进入登录页面
            let token = window.localStorage.getItem('token')
            if (token == undefined) {
                showToast('请先登录后再发表文章')
                return { name: 'LoginView' }

                // return false
            } else {
                return true
            }

        }
    },
    //发布日记
    {
        path: '/Rreleaser',
        name: 'Rreleaser',
        component: () => import("../views/RreleaserView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        },

        beforeEnter: () => {
            // 判断是否登录，没有登录进入登录页面
            let token = window.localStorage.getItem('token')

            if (token == undefined) {
                showToast('请先登录后再发表文章')
                return { name: 'LoginView' }
            } else {

            }

        }
    },
    //发布文章
    {
        path: '/Rreleasers',
        name: 'Rreleasers',
        component: () => import("../views/RreleasersView.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        },

        beforeEnter: () => {
            // 判断是否登录，没有登录进入登录页面
            let token = window.localStorage.getItem('token')

            if (token == undefined) {
                showToast('请先登录后再发表文章')
                return { name: 'LoginView' }
            } else {

            }

        }
    },
    {
        path: '/thingDetail',
        name: 'thingDetail',
        component: () => import("../views/thingDetail.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
    {
        path: '/ShopTrolley',
        name: 'ShopTrolley',
        component: () => import("../views/ShopTrolley.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    }, {
        path: '/OrderSettlement',
        name: 'OrderSettlement',
        component: () => import("../views/OrderSettlement.vue"),
        meta: {
            isBottomBar: true //不显示底部导航栏
        }
    },
]